<?php
require_once(dirname(__FILE__).'/scribe/Loader.php');

class Scribe extends CApplicationComponent
{
    public $host;
    public $port;
    public $category;
    public $fieldSeparator = '|';
    public $lineSeparator = "\n";
    
    public function init()
    {
        parent::init();
    }
    
    private function write($params)
    {
        try
        {
            $data = array();
            $data['category'] = $this->category.'_'.date('Ymd');
            $data['message'] = implode($this->fieldSeparator, $params).$this->lineSeparator;
            
            $transport = new TFramedTransport(new TSocket($this->host, $this->port, true));
            $transport->open();
            $protocol = new TBinaryProtocol($transport, false, false);
            $scribe_client = new scribeClient($protocol, $protocol);
            $scribe_client->Log(array(new LogEntry($data)));
            $transport->close();
        }
        catch(Exception $e)
        {
            echo $e->getMessage().PHP_EOL;
        }
    }
    
    public function log()
    {
        $params = array_merge(array(uniqid(), date('Y-m-d H:i:s')), func_get_args());
        $this->write($params);
    }
}